#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = N * 2;
int h[N], ne[M], e[M], w[M], idx;
LL dis[N], f[N][21];
int depth[N];
int arr[N];
int n, k;
void add(int a, int b, int c)
{
	e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int fa)
{
	depth[u] = depth[fa] + 1;
	f[u][0] = fa;
	for (int k = 1; k <= 20; k++) {
		f[u][k] = f[f[u][k - 1]][k - 1];
	}
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != fa) {
			dis[j] = dis[u] + w[i];
			dfs(j, u);
		}
	}
}
int get_lca(int a, int b)
{
	if (depth[a] < depth[b]) swap(a, b);
	int d = depth[a] - depth[b];
	////cout<<"d==="<<d<<endl;
	for (int i = 0; d; i++) {
		if (d & 1) {
			a = f[a][i];
		}
		d /= 2;
	}
	/*for (int i = 20; i >= 0; i--) {
		if (depth[f[a][i]] >= depth[b]) {
			a = f[a][i];
		}
	}*/
	if (a == b)return b;
	for (int i = 20; i >= 0; i--) {
		if (f[a][i] != f[b][i]) {
			a = f[a][i];
			b = f[b][i];
		}
	}
	return f[a][0];
}
LL get_dis(int a, int b)
{
	if (!a || !b)return 0;
	return dis[a] + dis[b] - 2 * dis[get_lca(a, b)];
}
int main()
{
	scanf("%d%d", &n, &k);
	memset(h, -1, sizeof(h));
	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		add(a, b, c);
		add(b, a, c);
	}
	dfs(1, 0);
	// 	for (int i = 1; i <= n; i++) {
	// 		cout << "i===" << i << "  depth[i]===" << depth[i] << endl;
	// 	}
	for (int i = 1; i <= k; i++) {
		scanf("%d", &arr[i]);
	}
	//	cout << " =====" << get_lca(5, 6) << endl;
	LL ans = 0;
	for (int i = 1; i <= k; i++) {
		//cout << arr[i] << "-->" << arr[i - 1] << " ===" << get_dis(arr[i], arr[i - 1]) << endl;
		ans += get_dis(arr[i], arr[i - 1]);
	}
	//cout << "ans==" << ans << endl;
	for (int i = 1; i <= k; i++) {
		printf("%lld ", ans - get_dis(arr[i - 1], arr[i])
			- get_dis(arr[i], arr[i + 1])
			+ get_dis(arr[i - 1], arr[i + 1]));
	}
	return 0;
}